﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Common;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.Event.SearchEventSender
{
    public partial class SearchEventSenderUserControl : UserControl
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                EventDataBind("未完成","top");
            }
        }

        protected void gvBC_DataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
            }

        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
             EventDataBind(this.RadioButtonList1.SelectedValue, "all");
        }


        private void EventDataBind(string status, string type)
        {
            using (EventProxy proxy = new EventProxy())
            {
                EventDataset.T_EventDataTable dt = proxy.GetMyEvent(SPContext.Current.Web.CurrentUser.Name, status, type);
                foreach (var item in dt)
	            {
                    int overDate = item.EndDate.Date.CompareTo(DateTime.Now.Date);
                    if (overDate > 0)
                    {
                        item.OverDate = "距离到期日期还有" + overDate + "天";
                    }
                    if (overDate == 0)
                    {
                        item.OverDate = "今天的工作";
                    }
                    if(overDate < 0)
                    {
                        item.OverDate = "已经过期" + overDate + "天";
                    }
	            }
                this.gvBC.DataSource = dt;
                this.gvBC.DataBind();
            }
        }      


     
    }
}
